package com.ichina.chat.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Files {
	public static void saveMessage(String user,String args) {
		try {
			File file = new File("d:\\messagetext");
			// 判读文件是否存在
			if (file.exists()) {
				BufferedReader br = new BufferedReader(new InputStreamReader(
						new FileInputStream(file)));
				String data = null;
				while ((data = br.readLine()) != null) {
					System.out.println(data);
				}
				OutputStreamWriter osw = new OutputStreamWriter(
						new FileOutputStream("d:\\messagetext"));
				osw.write(args, 0, args.length());
				osw.flush();
				// 关闭读文件的流
				br.close();
				osw.close();
			}else{
				 file.createNewFile(); 
			}
		} catch (Exception e) {
			e.printStackTrace();

		}
	}

}
